{extend name="admin/base" /}
{block name="resources"}
<style>
	.img-box{width:60px;height:60px;border:1px dashed #4685fd;position: relative;display: flex;    overflow: hidden;}
	.img-info{
		width: 100%;
		height: 100%;
		margin: 0 auto;
		line-height: 100%;
		vertical-align: middle;
	}
	.default-img-logo{display:inline-block;width:25px}
	dl.input-item-inline {
		width: 32%;
		clear: unset;
		display: inline-block;
		box-sizing: border-box;
	}
	dl.input-item-inline dd{
		width: 48%;
	}
	.item-line {
		width: 36%!important;
	}
	.hint {
		color: rgba(0,0,0,.3);
		margin-top: 20px;
	}
</style>

{/block}
{block name="main"}
<div class="set-style">
	<h4><span></span>升级条件</h4>
	<dl>
		<dt>高级红旗手升级条件：</dt>
		<dd>
			<input id="high_condition_num" type="number" value="{$reward_config.high_condition_num}" class="input-common" />
			<p class="hint">成为高级红旗手所属下级为中级红旗手的数量</p>
		</dd>
	</dl>
	<dl>
		<dt>特级红旗手升级条件：</dt>
		<dd>
			<input id="supper_condition_num" type="number" value="{$reward_config.supper_condition_num}" class="input-common" />
			<p class="hint">成为特级红旗手所属下级为中级红旗手的数量</p>
		</dd>
	</dl>
	<h4><span></span>免费使用产品时间</h4>
	<dl>
		<dt>高级红旗手使用时间：</dt>
		<dd>
			<input id="high_free_coupon_time" type="number" value="{$reward_config.high_free_coupon_time}" class="input-common" />
			<p class="hint">成为高级红旗手免费发放代金券时间 单位年</p>
		</dd>
	</dl>
	<dl>
		<dt>特级红旗手使用时间：</dt>
		<dd>
			<input id="supper_free_coupon_time" type="number" value="{$reward_config.supper_free_coupon_time}" class="input-common" />
			<p class="hint">成为特级红旗手免费发放代金券时间 单位年</p>
		</dd>
	</dl>
	<h4><span></span>奖励比率</h4>
	<dl>
		<dt>红旗手分享奖励比率：</dt>
		<dd>
			<input id="promoter_reward_rate" type="number" value="{$reward_config.promoter_reward_rate}" class="input-common" />
			<p class="hint">中级以上红旗手在下级首次购买自己已经购买的产品时可以获得的分享奖励比率，1-100</p>
		</dd>
	</dl>
	<dl>
		<dt>服务中心奖励比率：</dt>
		<dd>
			<input id="agent_reward_rate" type="number" value="{$reward_config.agent_reward_rate}" class="input-common" />
			<p class="hint">申请成为服务中心后下级在首次购买所属品类的产品时可以获得的服务奖励比率，1-100</p>
		</dd>
	</dl>
	<h4><span></span>代金券发放设置</h4>
	<dl>
		<dt>代金券发放时间：</dt>
		<dd>
			<input id="coupon_time_set" type="number" value="{$reward_config.coupon_time_set}" class="input-common" />
			<p class="hint">成为高级和特级红旗手系统会在一定时间内自动给红旗手发放对应产品的代金券，这里设置的为定期发放的时间，单位为月</p>
		</dd>
	</dl>
	<dl>
		<dt>优惠券发放数量：</dt>
		<dd>
			<input id="coupon_num_set" type="number" value="{$reward_config.coupon_num_set}" class="input-common" />
			<p class="hint">成为高级和特级红旗手系统会在一定时间内自动给红旗手发放对应产品的代金券，这里设置的为每次发放的数量</p>
		</dd>
	</dl>
	<h4><span></span>结算设置</h4>
	<dl>
		<dt>结算确认时间：</dt>
		<dd>
			<input id="settle_date_set" type="number" value="{$reward_config.settle_date_set}" class="input-common" />
			<p class="hint">系统自动在每月的该日期进行结算</p>
		</dd>
	</dl>
	<h4><span></span>图标设置</h4>
	<dl>
		<dt>红旗手图标：</dt>
		<dd class="item-line">
			<div class="img-box" style="width: 100px">
				<label style="margin:auto">
					{if condition="$reward_config.promoter_icon"}
					<img class="img-info" id="preview_promoter_icon" src="{:__IMG($reward_config.promoter_icon)}" data-src="{:__IMG($reward_config.promoter_icon)}" title="修改">
					{else/}
					<div class="default-img-logo default_promoter_icon">
						<img src="__STATIC__/blue/img/default.png">
					</div>
					<img class="img-info" id="preview_promoter_icon" src="" data-src="" style="display:none" title="修改">
					{/if}
					<input class="input-file" name="file_upload" id="upload_promoter_icon" type="file" onchange="imgUpload(this, 'promoter_icon');" title="上传" style="display:none">
				</label>
				<input type="hidden" id="promoter_icon" value="{if condition='$reward_config.promoter_icon'}{$reward_config.promoter_icon}{/if}" />
			</div>
		</dd>
	</dl>
	<dl>
		<dt>中级红旗手图标：</dt>
		<dd class="item-line">
			<div class="img-box" style="width: 100px">
				<label style="margin:auto">
					{if condition="$reward_config.middle_icon"}
					<img class="img-info" id="preview_middle_icon" src="{:__IMG($reward_config.middle_icon)}" data-src="{:__IMG($reward_config.middle_icon)}" title="修改">
					{else/}
					<div class="default-img-logo default_middle_icon">
						<img src="__STATIC__/blue/img/default.png">
					</div>
					<img class="img-info" id="preview_middle_icon" src="" data-src="" style="display:none" title="修改">
					{/if}
					<input class="input-file" name="file_upload" id="upload_middle_icon" type="file" onchange="imgUpload(this, 'middle_icon');" title="上传" style="display:none">
				</label>
				<input type="hidden" id="middle_icon" value="{if condition='$reward_config.promoter_icon'}{$reward_config.middle_icon}{/if}" />
			</div>
		</dd>
	</dl>
	<dl>
		<dt>高级红旗手图标：</dt>
		<dd class="item-line">
			<div class="img-box" style="width: 100px">
				<label style="margin:auto">
					{if condition="$reward_config.high_icon"}
					<img class="img-info" id="preview_high_icon" src="{:__IMG($reward_config.high_icon)}" data-src="{:__IMG($reward_config.high_icon)}" title="修改">
					{else/}
					<div class="default-img-logo default_high_icon">
						<img src="__STATIC__/blue/img/default.png">
					</div>
					<img class="img-info" id="preview_high_icon" src="" data-src="" style="display:none" title="修改">
					{/if}
					<input class="input-file" name="file_upload" id="upload_high_icon" type="file" onchange="imgUpload(this, 'high_icon');" title="上传" style="display:none">
				</label>
				<input type="hidden" id="high_icon" value="{if condition='$reward_config.promoter_icon'}{$reward_config.promoter_icon}{/if}" />
			</div>
		</dd>
	</dl>
	<dl>
		<dt>特级红旗手图标：</dt>
		<dd class="item-line">
			<div class="img-box" style="width: 100px">
				<label style="margin:auto">
					{if condition="$reward_config.supper_icon"}
					<img class="img-info" id="preview_supper_icon" src="{:__IMG($reward_config.supper_icon)}" data-src="{:__IMG($reward_config.supper_icon)}" title="修改">
					{else/}
					<div class="default-img-logo default_supper_icon">
						<img src="__STATIC__/blue/img/default.png">
					</div>
					<img class="img-info" id="preview_supper_icon" src="" data-src="" style="display:none" title="修改">
					{/if}
					<input class="input-file" name="file_upload" id="upload_supper_icon" type="file" onchange="imgUpload(this, 'supper_icon');" title="上传" style="display:none">
				</label>
				<input type="hidden" id="supper_icon" value="{if condition='$reward_config.promoter_icon'}{$reward_config.promoter_icon}{/if}" />
			</div>
		</dd>
	</dl>
	<dl>
		<dt>服务中心图标：</dt>
		<dd class="item-line">
			<div class="img-box" style="width: 100px">
				<label style="margin:auto">
					{if condition="$reward_config.region_agent_icon"}
					<img class="img-info" id="preview_region_agent_icon" src="{:__IMG($reward_config.region_agent_icon)}" data-src="{:__IMG($reward_config.region_agent_icon)}" title="修改">
					{else/}
					<div class="default-img-logo default_region_agent_icon">
						<img src="__STATIC__/blue/img/default.png">
					</div>
					<img class="img-info" id="preview_region_agent_icon" src="" data-src="" style="display:none" title="修改">
					{/if}
					<input class="input-file" name="file_upload" id="upload_region_agent_icon" type="file" onchange="imgUpload(this, 'region_agent_icon');" title="上传" style="display:none">
				</label>
				<input type="hidden" id="region_agent_icon" value="{if condition='$reward_config.region_agent_icon'}{$reward_config.region_agent_icon}{/if}" />
			</div>
		</dd>
	</dl>

	<dl>
		<dt></dt>
		<dd><button class="btn-common btn-big" onclick="setConfigAjax();">保存</button></dd>
	</dl>
</div>

<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>

<script>
    //图片上传
    function imgUpload(event, id) {
        var fileid = $(event).attr("id");
        var data = { 'file_path' : "config" };
        uploadFile({
            url: __URL(ADMINMAIN + '/config/uploadimage'),
            fileId: fileid,
            data : data,
            callBack: function (res) {
                if(res.code){
                    $("#" + id).val(res.data.path);
                    $("#text_" + id).val(res.data.path);
                    $("#preview_"+ id).attr("data-src",__IMG(res.data.path));
                    $("#preview_"+ id).attr("src", __IMG(res.data.path));
                    $("#preview_"+ id).show();
                    $("#preview_"+ id).parent().parent().css("border","0px");
                    $(".default_"+ id).hide();
                    showTip(res.message,"success");
                }else{
                    showTip(res.message,"error");
                }
            }
        });
    }

    function setConfigAjax() {
        var high_condition_num = Number($("#high_condition_num").val());
        var supper_condition_num = Number($("#supper_condition_num").val());

        var high_free_coupon_time = Number($("#high_free_coupon_time").val());
        var supper_free_coupon_time = Number($("#supper_free_coupon_time").val());

        var promoter_reward_rate = Number($("#promoter_reward_rate").val());
        var agent_reward_rate = Number($("#agent_reward_rate").val());

        var coupon_time_set = Number($("#coupon_time_set").val());
        var coupon_num_set = Number($("#coupon_num_set").val());

        var settle_date_set = Number($("#settle_date_set").val());

		var promoter_icon = $("#promoter_icon").val();
        var region_agent_icon = $("#region_agent_icon").val();
        var middle_icon = $("#middle_icon").val();
        var high_icon = $("#high_icon").val();
        var supper_icon = $("#supper_icon").val();

        if(high_condition_num <= 0){
            $("#high_condition_num").focus();
            showTip('成为高级所需数量需大于0', 'warning');
            return false;
		}
        if(supper_condition_num <= high_condition_num){
            $("#supper_condition_num").focus();
            showTip('成为特级所需数量需大于成为高级所需数量', 'warning');
            return false;
        }
        if(high_free_coupon_time <= 0){
            $("#high_free_coupon_time").focus();
            showTip('高级红旗手免费时间需大于0', 'warning');
            return false;
        }
        if(supper_free_coupon_time <= 0){
            $("#supper_free_coupon_time").focus();
            showTip('特级红旗手免费时间需大于0', 'warning');
            return false;
        }
        if(promoter_reward_rate <= 0 && promoter_reward_rate >= 100){
            $("#promoter_reward_rate").focus();
            showTip('分享奖励比率需在1-100之间', 'warning');
            return false;
        }
        if(agent_reward_rate <= 0 && agent_reward_rate >= 100){
            $("#agent_reward_rate").focus();
            showTip('服务奖励比率需在1-100之间', 'warning');
            return false;
        }
        if(coupon_time_set <= 0){
            $("#coupon_time_set").focus();
            showTip('代金券发放时间需大于0', 'warning');
            return false;
        }
        if(coupon_num_set <= 0){
            $("#coupon_num_set").focus();
            showTip('代金券发放数量需大于0', 'warning');
            return false;
        }
        if(settle_date_set <= 0 || settle_date_set > 31){
            $("#coupon_num_set").focus();
            showTip('请输入正确的结算日期', 'warning');
            return false;
        }
		if(promoter_icon == ''){
            showTip('请上传红旗手图标', 'warning');
            return false;
		}
        if(middle_icon == ''){
            showTip('请上传中级红旗手图标', 'warning');
            return false;
        }
        if(high_icon == ''){
            showTip('请上传高级红旗手图标', 'warning');
            return false;
        }
        if(supper_icon == ''){
            showTip('请上传特级红旗手图标', 'warning');
            return false;
        }
        if(region_agent_icon == ''){
            showTip('服务中心图标', 'warning');
            return false;
        }

        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/config/rewardSet')}",
            data : {
                'high_condition_num' : high_condition_num,
                'supper_condition_num' : supper_condition_num,
                'high_free_coupon_time' : high_free_coupon_time,
                'supper_free_coupon_time' : supper_free_coupon_time,
                'promoter_reward_rate' : promoter_reward_rate,
                'agent_reward_rate' : agent_reward_rate,
                'coupon_time_set' : coupon_time_set,
                'coupon_num_set' : coupon_num_set,
                'settle_date_set' : settle_date_set,
				'promoter_icon' : promoter_icon,
				'region_agent_icon' : region_agent_icon,
				'middle_icon' : middle_icon,
				'high_icon' : high_icon,
				'supper_icon' : supper_icon
            },
            success : function(data) {
                if (data["code"] > 0) {
                    showTip(data["message"],"success");
                    setTimeout(function(){window.location.reload();},2000);
                } else {
                    showTip(res.message,"error");
                }
            }
        });
    }
</script>
{/block}